package com.yt.user.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.yt.user.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yt.user.mapper.SysRoleMapper;
import com.yt.user.models.service.ISysRoleService;
import com.yt.user.models.bo.SysRoleSaveBO;
import com.yt.user.models.dto.SysRoleDTO;

import java.util.List;

/**
 * 登录控制器
 *
 * @author xieyanfei
 * @Date 2025-09-05 18:01:12
 */
@DubboService
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleDTO> implements ISysRoleService{

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(SysRoleSaveBO saveBO) {
        SysRoleDTO dto = new SysRoleDTO();
        BeanUtils.copyProperties(saveBO,dto);
        Long id = ymlConfig.getPkId();
        dto.setId(id);
        return this.insert(dto);
    }
    // 修改文件: yt-user/yt-user-server/src/main/java/com/yt/user/service/SysRoleServiceImpl.java
    @Override
    public SysRoleDTO selectByRoleName(String roleName) {
        // 对于 MyBatis Plus 2.x 版本，使用 EntityWrapper 和 selectList
        Wrapper<SysRoleDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("role_name", roleName);
        List<SysRoleDTO> list = baseMapper.selectList(wrapper);
        return list.isEmpty() ? null : list.get(0);
    }

    @Override
    public boolean assignPermissions(Long roleId, List<Long> permissionIds) {
        // 实际项目中实现权限分配逻辑
        return true;
    }
}
